<!-- <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>课表系统</title>
</head>
<body>
<h2>注册用户</h2>
<input id="r_username" placeholder="用户名" />
<input id="r_password" type="password" placeholder="密码" />
<button onclick="register()">注册</button>

<h2>登录</h2>
<input id="l_username" placeholder="用户名" />
<input id="l_password" type="password" placeholder="密码" />
<button onclick="login()">登录</button>

<div id="course-section" style="display:none;">
    <h2>添加课程</h2>
    <input id="name" placeholder="课程名" />
    <input id="teacher" placeholder="教师" />
    <input id="place" placeholder="地点" />
    <input id="weekDay" placeholder="星期几" />
    <input id="period" placeholder="第几节" />
    <button onclick="addCourse()">添加</button>

    <h2>我的课表</h2>
    <ul id="courseList"></ul>
</div>

<script>
    let userId = '';

    function register() {
        fetch('/api/user/register', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                username: document.getElementById('r_username').value,
                password: document.getElementById('r_password').value
            })
        }).then(res => res.text()).then(alert);
    }

    function login() {
        fetch('/api/user/login', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                username: document.getElementById('l_username').value,
                password: document.getElementById('l_password').value
            })
        }).then(res => res.text()).then(id => {
            if (id.length === 36) {
                userId = id;
                document.getElementById('course-section').style.display = 'block';
                loadCourses();
            } else {
                alert(id);
            }
        });
    }

    function addCourse() {
        fetch('/api/course/add', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                userId: userId,
                name: document.getElementById('name').value,
                teacher: document.getElementById('teacher').value,
                place: document.getElementById('place').value,
                weekDay: document.getElementById('weekDay').value,
                period: document.getElementById('period').value
            })
        }).then(res => res.text()).then(alert);
    }

    function loadCourses() {
        fetch('/api/course/list/' + userId)
            .then(res => res.json())
            .then(data => {
                let ul = document.getElementById('courseList');
                ul.innerHTML = '';
                data.forEach(c => {
                    let li = document.createElement('li');
                    li.textContent = `${c.weekDay} 第${c.period}节：${c.name} @${c.place}`;
                    ul.appendChild(li);
                });
            });
    }
</script>
</body>
</html> -->